package com.jzg.jcptadmin.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;

import com.jzg.jcptadmin.R;
import com.jzg.jcptadmin.base.BaseActivity;
import com.jzg.jcptadmin.constant.Constant;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by jzg on 2015/12/28.
 * 单选界面
 */
public class DocumentsConfirmActivity extends BaseActivity implements View.OnClickListener {

    @Bind(R.id.checkbox1)
    CheckBox checkbox1;
    @Bind(R.id.checkbox2)
    CheckBox checkbox2;
    @Bind(R.id.checkbox3)
    CheckBox checkbox3;
    @Bind(R.id.checkbox4)
    CheckBox checkbox4;
    @Bind(R.id.title_content)
    TextView titleContent;
    @Bind(R.id.tv_right)
    TextView tvRight;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_documents_confirm);
        ButterKnife.bind(this);
        initview();
        String str = getIntent().getStringExtra(Constant.ACTIVITY_ZHENGJIANQUEREN).replaceAll(" ", "");

        String[] strs = str.split("\\|");
        for (int i = 0; i < strs.length; i++) {
            if (strs[i].equals(checkbox1.getText().toString().trim())) {
                checkbox1.setChecked(true);
            }
            if (strs[i].equals(checkbox2.getText().toString().trim())) {
                checkbox2.setChecked(true);
            }
            if (strs[i].equals(checkbox3.getText().toString().trim())) {
                checkbox3.setChecked(true);
            }
            if (strs[i].equals(checkbox4.getText().toString().trim())) {
                checkbox4.setChecked(true);
            }

        }


    }

    public void onSave() {
        Intent intent = new Intent();
        String s = "";
        String s1 = "";

        if (!checkbox1.isChecked() && !checkbox2.isChecked() && !checkbox3.isChecked() && !checkbox4.isChecked()) {
            Toast.makeText(this, "请选择", Toast.LENGTH_SHORT).show();
            return;
        }
        if (checkbox1.isChecked()) {
            s = checkbox1.getText().toString().trim() + " | ";
            s1 = "1,";

        }
        if (checkbox2.isChecked()) {
            s = s + checkbox2.getText().toString().trim() + " | ";
            s1 = s1 + "2,";
        }
        if (checkbox3.isChecked()) {
            s = s + checkbox3.getText().toString().trim() + " | ";
            s1 = s1 + "3,";
        }
        if (checkbox4.isChecked()) {
            s = s + checkbox4.getText().toString().trim() + " | ";
            s1 = s1 + "4,";
        }
        intent.putExtra(Constant.ACTIVITY_ZHENGJIANQUEREN, s);
        intent.putExtra(Constant.ACTIVITY_ZHENGJIANQUERENID, s1);
        setResult(Activity.RESULT_OK, intent);
        finish();
    }

    private void initview() {
        titleContent.setText("请选择证件");


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.tv_right})
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_right:
                onSave();
                break;
            default:

                break;
        }
    }
}
